package com.gitee.swsk33.mapstructdemo.structmapper;

import com.gitee.swsk33.mapstructdemo.dataobject.WeaponDO;
import com.gitee.swsk33.mapstructdemo.dto.WeaponDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.UUID;

/**
 * 先使用imports导入类，然后才能在表达式使用该类
 * 否则要使用该类的全限定名
 */
@Mapper(imports = UUID.class)
public interface WeaponMapper {

	WeaponMapper INSTANCE = Mappers.getMapper(WeaponMapper.class);

	/**
	 * 将武器DTO对象转换成DO
	 */
	@Mapping(target = "figureId", ignore = true)
	@Mapping(target = "name", defaultValue = "未命名武器")
	WeaponDO toWeaponDO(WeaponDTO weaponDTO);

	/**
	 * 将武器DTO转换成DO，并使用表达式填入figureId属性
	 */
	@Mapping(target = "figureId", expression = "java(figureId)")
	WeaponDO toWeaponDOWithFigureId(WeaponDTO weaponDTO, int figureId);

	/**
	 * 定义将武器DTO列表转换成DO列表的方法
	 */
	List<WeaponDO> toWeaponDOList(List<WeaponDTO> weaponDTOList);

	/**
	 * 定义将武器DO列表转换成DTO列表的方法
	 */
	List<WeaponDTO> toWeaponDTOList(List<WeaponDO> weaponDOList);

	/**
	 * 将武器DO转换成DTO
	 * 对于name属性，使用表达式调用Java代码生成UUID
	 */
	@Mapping(target = "name", expression = "java(UUID.randomUUID().toString())")
	WeaponDTO toDTOExpressionDemo(WeaponDO weaponDO);

}